package controllers;

import entidades.Detalleventa;
import javax.inject.Named;
import javax.faces.view.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.inject.Inject;

@Named(value = "detalleventaController")
@ViewScoped
public class DetalleventaController extends AbstractController<Detalleventa> {

    @Inject
    private VentaController codventaController;
    @Inject
    private ProductoController codproductoController;

    public DetalleventaController() {
        // Inform the Abstract parent controller of the concrete Detalleventa?cap_first Entity
        super(Detalleventa.class);
    }

    /**
     * Resets the "selected" attribute of any parent Entity controllers.
     */
    public void resetParents() {
        codventaController.setSelected(null);
        codproductoController.setSelected(null);
    }

    /**
     * Sets the "selected" attribute of the Venta controller in order to display
     * its data in a dialog. This is reusing existing the existing View dialog.
     *
     * @param event Event object for the widget that triggered an action
     */
    public void prepareCodventa(ActionEvent event) {
        if (this.getSelected() != null && codventaController.getSelected() == null) {
            codventaController.setSelected(this.getSelected().getCodventa());
        }
    }

    /**
     * Sets the "selected" attribute of the Producto controller in order to
     * display its data in a dialog. This is reusing existing the existing View
     * dialog.
     *
     * @param event Event object for the widget that triggered an action
     */
    public void prepareCodproducto(ActionEvent event) {
        if (this.getSelected() != null && codproductoController.getSelected() == null) {
            codproductoController.setSelected(this.getSelected().getCodproducto());
        }
    }
}
